package com.fanshuai.springcloud.controller;

import org.springframework.cloud.gateway.config.PropertiesRouteDefinitionLocator;
import org.springframework.cloud.gateway.route.*;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import javax.annotation.Resource;

@RestController
@RequestMapping("/gateway")
public class GatewayController {
    @Resource
    private RouteDefinitionLocator routeDefinitionLocator;
    @Resource
    private PropertiesRouteDefinitionLocator propertiesRouteDefinitionLocator;
    @Resource
    private InMemoryRouteDefinitionRepository inMemoryRouteDefinitionRepository;
    @Resource
    RouteLocator routeLocator;

    @GetMapping("/routes")
    public Flux<RouteDefinition> routes1() {
        return routeDefinitionLocator.getRouteDefinitions();
    }

    @GetMapping("/properties/routes")
    public Flux<RouteDefinition> routes2() {
        return propertiesRouteDefinitionLocator.getRouteDefinitions();
    }

    @GetMapping("/inmemory/routes")
    public Flux<RouteDefinition> routes3() {
        return inMemoryRouteDefinitionRepository.getRouteDefinitions();
    }

    @GetMapping("/routes2")
    public Flux<Route> routes4() {
        return routeLocator.getRoutes();
    }
}
